package be.jas.mvc.base.model.fam;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: jasmien
 * Date: 2/08/13
 * Time: 13:27
 * To change this template use File | Settings | File Templates.
 */
public abstract class AbstractReasoner extends AbstractModelWithID {

    protected Map<String, FamFeature> featureMap;

    public AbstractReasoner(String id, String description) {
        super(id, description);
        featureMap = new HashMap<String, FamFeature>();
    }

    public FamFeature getFeature(String id){
        return this.featureMap.get(id);
    }

    public void addFeature(FamFeature famFeature) {
        this.featureMap.put(famFeature.getId(), famFeature);
    }

    public List<FamFeature> getFeatures(){
        Collection<FamFeature> allfeatures = featureMap.values();
        List<FamFeature> features = new ArrayList<FamFeature>(allfeatures);
        for(FamFeature feature : allfeatures){
            for(FamFeature subFeature : feature.getAllFeatures()){
                features.remove(subFeature);
            }
        }
        return features;
    }

    public Collection<FamFeature> getAllFeatures(){
        return featureMap.values();
    }

    public int getNumberOfFeatures() {
        return featureMap.size();
    }

    public Map<String, FamFeature> getFeatureMap() {
        return featureMap;
    }

    public void setFeatureMap(Map<String, FamFeature> featureMap) {
        this.featureMap = featureMap;
    }

    public String toString(String prefix){
        String ret = super.toString() + "\n";
        ret +=  prefix + "Features:\n";
        for(Map.Entry<String, FamFeature> entry : featureMap.entrySet()){
            ret += entry.getValue().toString("\t") + "\n";
        }
        return ret;
    }


}
